{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ee19391f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>天气状况</th>\n",
       "      <th>最高温度</th>\n",
       "      <th>最低温度</th>\n",
       "      <th>白天风力风向</th>\n",
       "      <th>夜晚风力风向</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018/1/1</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>12℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018/1/1</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>12℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018/1/2</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>15℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018/1/3</td>\n",
       "      <td>多云/阴</td>\n",
       "      <td>23℃</td>\n",
       "      <td>15℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018/1/4</td>\n",
       "      <td>多云/小雨</td>\n",
       "      <td>21℃</td>\n",
       "      <td>16℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1340</th>\n",
       "      <td>2021/8/27</td>\n",
       "      <td>雷阵雨/雷阵雨</td>\n",
       "      <td>35℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1341</th>\n",
       "      <td>2021/8/28</td>\n",
       "      <td>雷阵雨/多云</td>\n",
       "      <td>33℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1342</th>\n",
       "      <td>2021/8/29</td>\n",
       "      <td>雷阵雨/雷阵雨</td>\n",
       "      <td>32℃</td>\n",
       "      <td>25℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1343</th>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>阵雨/阵雨</td>\n",
       "      <td>34℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1344</th>\n",
       "      <td>2021/8/31</td>\n",
       "      <td>雷阵雨/阵雨</td>\n",
       "      <td>32℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1345 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期     天气状况 最高温度 最低温度    白天风力风向    夜晚风力风向\n",
       "0      2018/1/1    多云/多云  22℃  12℃  无持续风向<3级  无持续风向<3级\n",
       "1      2018/1/1    多云/多云  22℃  12℃  无持续风向<3级  无持续风向<3级\n",
       "2      2018/1/2    多云/多云  22℃  15℃  无持续风向<3级  无持续风向<3级\n",
       "3      2018/1/3     多云/阴  23℃  15℃  无持续风向<3级  无持续风向<3级\n",
       "4      2018/1/4    多云/小雨  21℃  16℃  无持续风向<3级  无持续风向<3级\n",
       "...         ...      ...  ...  ...       ...       ...\n",
       "1340  2021/8/27  雷阵雨/雷阵雨  35℃  26℃    北风1-2级    北风1-2级\n",
       "1341  2021/8/28   雷阵雨/多云  33℃  26℃    北风1-2级    北风1-2级\n",
       "1342  2021/8/29  雷阵雨/雷阵雨  32℃  25℃    北风1-2级    北风1-2级\n",
       "1343  2021/8/30    阵雨/阵雨  34℃  26℃    北风1-2级    北风1-2级\n",
       "1344  2021/8/31   雷阵雨/阵雨  32℃  26℃    北风1-2级    北风1-2级\n",
       "\n",
       "[1345 rows x 6 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd \n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "#设置绘图时显示的中文字体\n",
    "plt.rcParams['font.sans-serif']=['Microsoft YaHei']\n",
    "weather_info=pd.read_csv('td03.csv')\n",
    "weather_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2aa49f0f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1339\n",
      "1345\n"
     ]
    }
   ],
   "source": [
    "std_rng=pd.date_range(start='2018/1/1',end='2021/8/31',freq='D')\n",
    "print(len(std_rng))\n",
    "print(len(weather_info))#天气数据比预期多，检查重复值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "89a61917",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weather_info.duplicated().sum()#天气数据有6个重复值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6437ebad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>天气状况</th>\n",
       "      <th>最高温度</th>\n",
       "      <th>最低温度</th>\n",
       "      <th>白天风力风向</th>\n",
       "      <th>夜晚风力风向</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018/1/1</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>12℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>917</th>\n",
       "      <td>2020/7/4</td>\n",
       "      <td>雷阵雨/雷阵雨</td>\n",
       "      <td>33℃</td>\n",
       "      <td>27℃</td>\n",
       "      <td>无持续风向1-2级</td>\n",
       "      <td>无持续风向1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>919</th>\n",
       "      <td>2020/7/5</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>35℃</td>\n",
       "      <td>27℃</td>\n",
       "      <td>无持续风向1-2级</td>\n",
       "      <td>无持续风向1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1071</th>\n",
       "      <td>2020/12/3</td>\n",
       "      <td>晴/晴</td>\n",
       "      <td>21℃</td>\n",
       "      <td>11℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1255</th>\n",
       "      <td>2021/6/4</td>\n",
       "      <td>大雨/小雨</td>\n",
       "      <td>28℃</td>\n",
       "      <td>23℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1256</th>\n",
       "      <td>2021/6/4</td>\n",
       "      <td>大雨/小雨</td>\n",
       "      <td>28℃</td>\n",
       "      <td>23℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期     天气状况 最高温度 最低温度     白天风力风向     夜晚风力风向\n",
       "1      2018/1/1    多云/多云  22℃  12℃   无持续风向<3级   无持续风向<3级\n",
       "917    2020/7/4  雷阵雨/雷阵雨  33℃  27℃  无持续风向1-2级  无持续风向1-2级\n",
       "919    2020/7/5    多云/多云  35℃  27℃  无持续风向1-2级  无持续风向1-2级\n",
       "1071  2020/12/3      晴/晴  21℃  11℃     北风1-2级     北风1-2级\n",
       "1255   2021/6/4    大雨/小雨  28℃  23℃     北风1-2级     北风1-2级\n",
       "1256   2021/6/4    大雨/小雨  28℃  23℃     北风1-2级     北风1-2级"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weather_info[weather_info.duplicated()]#打印重复值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "177c693c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>天气状况</th>\n",
       "      <th>最高温度</th>\n",
       "      <th>最低温度</th>\n",
       "      <th>白天风力风向</th>\n",
       "      <th>夜晚风力风向</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018/1/1</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>12℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018/1/2</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>15℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018/1/3</td>\n",
       "      <td>多云/阴</td>\n",
       "      <td>23℃</td>\n",
       "      <td>15℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018/1/4</td>\n",
       "      <td>多云/小雨</td>\n",
       "      <td>21℃</td>\n",
       "      <td>16℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2018/1/5</td>\n",
       "      <td>阴/小雨</td>\n",
       "      <td>19℃</td>\n",
       "      <td>13℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1340</th>\n",
       "      <td>2021/8/27</td>\n",
       "      <td>雷阵雨/雷阵雨</td>\n",
       "      <td>35℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1341</th>\n",
       "      <td>2021/8/28</td>\n",
       "      <td>雷阵雨/多云</td>\n",
       "      <td>33℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1342</th>\n",
       "      <td>2021/8/29</td>\n",
       "      <td>雷阵雨/雷阵雨</td>\n",
       "      <td>32℃</td>\n",
       "      <td>25℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1343</th>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>阵雨/阵雨</td>\n",
       "      <td>34℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1344</th>\n",
       "      <td>2021/8/31</td>\n",
       "      <td>雷阵雨/阵雨</td>\n",
       "      <td>32℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1339 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期     天气状况 最高温度 最低温度    白天风力风向    夜晚风力风向\n",
       "0      2018/1/1    多云/多云  22℃  12℃  无持续风向<3级  无持续风向<3级\n",
       "2      2018/1/2    多云/多云  22℃  15℃  无持续风向<3级  无持续风向<3级\n",
       "3      2018/1/3     多云/阴  23℃  15℃  无持续风向<3级  无持续风向<3级\n",
       "4      2018/1/4    多云/小雨  21℃  16℃  无持续风向<3级  无持续风向<3级\n",
       "5      2018/1/5     阴/小雨  19℃  13℃  无持续风向<3级  无持续风向<3级\n",
       "...         ...      ...  ...  ...       ...       ...\n",
       "1340  2021/8/27  雷阵雨/雷阵雨  35℃  26℃    北风1-2级    北风1-2级\n",
       "1341  2021/8/28   雷阵雨/多云  33℃  26℃    北风1-2级    北风1-2级\n",
       "1342  2021/8/29  雷阵雨/雷阵雨  32℃  25℃    北风1-2级    北风1-2级\n",
       "1343  2021/8/30    阵雨/阵雨  34℃  26℃    北风1-2级    北风1-2级\n",
       "1344  2021/8/31   雷阵雨/阵雨  32℃  26℃    北风1-2级    北风1-2级\n",
       "\n",
       "[1339 rows x 6 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weather_info.drop_duplicates()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5d70309f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#输出数据\n",
    "column=['日期','天气状况','最高温度','最低温度','白天风力风向','夜晚风力风向']\n",
    "td03_new=pd.DataFrame(columns=column,data=weather_info)\n",
    "td03_new.to_csv('td03_new.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7ec78acb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>日期</th>\n",
       "      <th>天气状况</th>\n",
       "      <th>最高温度</th>\n",
       "      <th>最低温度</th>\n",
       "      <th>白天风力风向</th>\n",
       "      <th>夜晚风力风向</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2018/1/1</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>12℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2018/1/1</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>12℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>2018/1/2</td>\n",
       "      <td>多云/多云</td>\n",
       "      <td>22℃</td>\n",
       "      <td>15℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>2018/1/3</td>\n",
       "      <td>多云/阴</td>\n",
       "      <td>23℃</td>\n",
       "      <td>15℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2018/1/4</td>\n",
       "      <td>多云/小雨</td>\n",
       "      <td>21℃</td>\n",
       "      <td>16℃</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "      <td>无持续风向&lt;3级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1340</th>\n",
       "      <td>1340</td>\n",
       "      <td>2021/8/27</td>\n",
       "      <td>雷阵雨/雷阵雨</td>\n",
       "      <td>35℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1341</th>\n",
       "      <td>1341</td>\n",
       "      <td>2021/8/28</td>\n",
       "      <td>雷阵雨/多云</td>\n",
       "      <td>33℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1342</th>\n",
       "      <td>1342</td>\n",
       "      <td>2021/8/29</td>\n",
       "      <td>雷阵雨/雷阵雨</td>\n",
       "      <td>32℃</td>\n",
       "      <td>25℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1343</th>\n",
       "      <td>1343</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>阵雨/阵雨</td>\n",
       "      <td>34℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1344</th>\n",
       "      <td>1344</td>\n",
       "      <td>2021/8/31</td>\n",
       "      <td>雷阵雨/阵雨</td>\n",
       "      <td>32℃</td>\n",
       "      <td>26℃</td>\n",
       "      <td>北风1-2级</td>\n",
       "      <td>北风1-2级</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1345 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Unnamed: 0         日期     天气状况 最高温度 最低温度    白天风力风向    夜晚风力风向\n",
       "0              0   2018/1/1    多云/多云  22℃  12℃  无持续风向<3级  无持续风向<3级\n",
       "1              1   2018/1/1    多云/多云  22℃  12℃  无持续风向<3级  无持续风向<3级\n",
       "2              2   2018/1/2    多云/多云  22℃  15℃  无持续风向<3级  无持续风向<3级\n",
       "3              3   2018/1/3     多云/阴  23℃  15℃  无持续风向<3级  无持续风向<3级\n",
       "4              4   2018/1/4    多云/小雨  21℃  16℃  无持续风向<3级  无持续风向<3级\n",
       "...          ...        ...      ...  ...  ...       ...       ...\n",
       "1340        1340  2021/8/27  雷阵雨/雷阵雨  35℃  26℃    北风1-2级    北风1-2级\n",
       "1341        1341  2021/8/28   雷阵雨/多云  33℃  26℃    北风1-2级    北风1-2级\n",
       "1342        1342  2021/8/29  雷阵雨/雷阵雨  32℃  25℃    北风1-2级    北风1-2级\n",
       "1343        1343  2021/8/30    阵雨/阵雨  34℃  26℃    北风1-2级    北风1-2级\n",
       "1344        1344  2021/8/31   雷阵雨/阵雨  32℃  26℃    北风1-2级    北风1-2级\n",
       "\n",
       "[1345 rows x 7 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weather_info=pd.read_csv('td03_new.csv')\n",
    "weather_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ab3c96f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#对天气数据做处理\n",
    "#将日期类型转化为datetime\n",
    "weather_info['日期']=weather_info['日期'].map(lambda x : pd.to_datetime(x))\n",
    "#设置日期列为行索引\n",
    "weather_info=weather_info.set_index(['日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bd00653a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Unnamed: 0    0\n",
       "天气状况          0\n",
       "最高温度          0\n",
       "最低温度          0\n",
       "白天风力风向        0\n",
       "夜晚风力风向        0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#缺失值检查\n",
    "(weather_info.isnull()).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "930d654b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['多云/多云' '多云/阴' '多云/小雨' '阴/小雨' '小雨-中雨/中雨-大雨' '大雨/中雨' '中雨/小雨-中雨' '小雨/阴'\n",
      " '晴/晴' '阴/阴' '多云/局部多云' '阴/阵雨' '小雨/小雨' '小雨/多云' '多云/晴' '阴/多云' '晴/多云' '多云/雾'\n",
      " '雷阵雨/雷阵雨' '雷阵雨/小雨-中雨' '雷阵雨/多云' '雾/雾' '中雨/大雨' '阵雨/多云' '多云/阵雨' '阵雨/阴'\n",
      " '中雨/小雨' '小雨-中雨/阵雨' '中雨/阵雨' '小雨-中雨/雷阵雨' '雷阵雨/阴' '小雨-中雨/中雨' '阵雨/阵雨'\n",
      " '中雨-大雨/中雨-大雨' '雷阵雨/大雨' '中雨-大雨/中雨' '晴间多云/多云' '雷阵雨/阵雨' '中雨/中雨' '中雨/雷阵雨'\n",
      " '大雨/大雨' '暴雨/暴雨' '大雨/暴雨' '大雨/雷阵雨' '阵雨/雷阵雨' '大雨/阵雨' '中雨-大雨/阵雨' '暴雨/阵雨'\n",
      " '大雨/阴' '阵雨/中雨' '雷阵雨/中雨' '暴雨/大雨' '大雨/小雨' '小到中雨/小雨' '小雨/中雨' '阴/中雨' '多云/中雨'\n",
      " '中到大雨/中到大雨' '小到中雨/小到中雨' '小雨/小到中雨' '中雨/小到中雨' '暴雨/中到大雨' '阵雨/大雨' '中到大雨/小雨'\n",
      " '中雨/暴雨' '小雨/阵雨' '中到大雨/中雨' '中雨/大到暴雨' '中雨/多云' '大雨/大到暴雨' '雷阵雨/大到暴雨' '暴雨/雷阵雨'\n",
      " '中到大雨/阵雨' '多云/雷阵雨' '晴/阴' '中到大雨/雷阵雨' '晴/阵雨' '暴雨/中雨' '雷阵雨/中到大雨' '阴/雷阵雨'\n",
      " '雷阵雨/暴雨' '大到暴雨/小雨' '雷阵雨/小雨' '小雨/雷阵雨']\n",
      "84\n"
     ]
    }
   ],
   "source": [
    "#查看天气列取值种类\n",
    "print(weather_info['天气状况'].unique())\n",
    "#查看天气列种类个数\n",
    "print(len(weather_info['天气状况'].unique()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a39609d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "def extract_weather_info(str):\n",
    "    std_weather_info=['晴','多云','阴','雾','小雨','中雨','大雨','暴雨','阵雨']\n",
    "    find=False\n",
    "    for weather in std_weather_info:\n",
    "        if weather in str:\n",
    "            find=True\n",
    "            str=weather\n",
    "        else:\n",
    "            pass\n",
    "    if find is False:\n",
    "        print(str+' no find!')\n",
    "    return str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "df4b639f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#使用extract_weather_info（）提取天气状况信息\n",
    "weather_info['天气状况']=weather_info['天气状况'].map(lambda x : extract_weather_info(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3792fd93",
   "metadata": {},
   "outputs": [],
   "source": [
    "#定义函数量化天气状况,类型过多可以随机取进行统一归属\n",
    "def str_to_int(str):\n",
    "    dict={'晴':1,'多云':2,'阴':3,'雾':4,'小雨':5,'中雨':6,'大雨':7,'暴雨':8,'阵雨':9}\n",
    "    return dict[str]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9047426e",
   "metadata": {},
   "outputs": [],
   "source": [
    "#使用str_to_int()量化\n",
    "weather_info['天气状况']=weather_info['天气状况'].map(lambda x : str_to_int(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "57cf41ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "weather_info['最高温度']=weather_info['最高温度'].str.strip('℃')\n",
    "weather_info['最低温度']=weather_info['最低温度'].str.strip('℃')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1e9a198c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['无持续风向<3级' '北风4～5级' '微风<3级' '北风3' '东北风3～4级' '北风3～4级' '南风3～4级' '南风4～5级'\n",
      " '东北偏东风2' '无持续风向微风' '无持续风向1-2级' '东风3-4级' '东南风4-5级' '东风3～4级' '东北风3-4级'\n",
      " '东风8-9级' '东南风3-4级' '北风3-4级' '北风4-5级' '南风3-4级' '南风1-2级' '东南风1-2级'\n",
      " '西南风3-4级' '东风1-2级' '北风1-2级' '东北风1-2级' '西南风1-2级']\n",
      "27\n"
     ]
    }
   ],
   "source": [
    "#查看天气列取值种类\n",
    "print(weather_info['白天风力风向'].unique())\n",
    "#查看天气列种类个数\n",
    "print(len(weather_info['白天风力风向'].unique()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "6d880b59",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['无持续风向<3级' '北风4～5级' '北风3～4级' '微风<3级' '北风3' '东北偏东风2' '无持续风向微风' '无持续风向1-2级'\n",
      " '东风3-4级' '东南风4-5级' '东南风3～4级' '东北风3-4级' '东风8-9级' '东南风3-4级' '北风3-4级'\n",
      " '北风4-5级' '南风3-4级' '南风1-2级' '东南风1-2级' '西南风3-4级' '东风1-2级' '北风1-2级'\n",
      " '东北风1-2级' '西南风1-2级']\n",
      "24\n"
     ]
    }
   ],
   "source": [
    "#查看天气列取值种类\n",
    "print(weather_info['夜晚风力风向'].unique())\n",
    "#查看天气列种类个数\n",
    "print(len(weather_info['夜晚风力风向'].unique()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "076e21a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "#定义函数量化白天风力风向\n",
    "def bai_to_int(str):\n",
    "    dict={'无持续风向<3级':1,'北风4～5级':2,'微风<3级':3,'北风3':4,'东北风3～4级':5,\\\n",
    "          '北风3～4级':6,'南风3～4级':7,'南风4～5级':8,'东北偏东风2':9,'无持续风向微风':10,\\\n",
    "          '无持续风向1-2级':11,'东风3-4级':12,'东南风4-5级':13,'东风3～4级':14,'东北风3-4级':15,\\\n",
    "         '东风8-9级':16,'东南风3-4级':17,'北风3-4级':18,'北风4-5级':19,'南风3-4级':20,\\\n",
    "          '南风1-2级':21,'东南风1-2级':22,'西南风3-4级':23,'东风1-2级':24,'北风1-2级':25,\\\n",
    "          '东北风1-2级':26,'西南风1-2级':27}\n",
    "    return dict[str]\n",
    "#使用bai_to_int()量化\n",
    "weather_info['白天风力风向']=weather_info['白天风力风向'].map(lambda x : bai_to_int(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c07c053a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#定义函数量化夜晚风力风向\n",
    "def wan_to_int(str):\n",
    "    dict={'无持续风向<3级':1,'北风4～5级':2,'微风<3级':3,'北风3～4级':4,'北风3':5,\\\n",
    "          '东北偏东风2':6,'无持续风向微风':7,'无持续风向1-2级':8,'东风3-4级':9,'东南风4-5级':10,\\\n",
    "          '东南风3～4级':11,'东北风3-4级':12,'东风8-9级':13,'东南风3-4级':14,'北风3-4级':15,\\\n",
    "         '北风4-5级':16,'南风3-4级':17,'南风1-2级':18,'东南风1-2级':19,'西南风3-4级':20,\\\n",
    "          '东风1-2级':21,'北风1-2级':22,'东北风1-2级':23,'西南风1-2级':24}\n",
    "    return dict[str]\n",
    "#使用wan_to_int()量化\n",
    "weather_info['夜晚风力风向']=weather_info['夜晚风力风向'].map(lambda x : wan_to_int(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "4c2528d4",
   "metadata": {},
   "outputs": [],
   "source": [
    "#输出数据\n",
    "#column=['日期','天气状况','最高温度','最低温度','白天风力风向','夜晚风力风向']\n",
    "#td003=pd.DataFrame(columns=column,data=weather_info)\n",
    "#td003.to_csv('td_weather.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3e9a41eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>天气状况</th>\n",
       "      <th>最高温度</th>\n",
       "      <th>最低温度</th>\n",
       "      <th>白天风力风向</th>\n",
       "      <th>夜晚风力风向</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>日期</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-01-01</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>22</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-01</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>22</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-02</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>22</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-03</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-01-04</th>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>21</td>\n",
       "      <td>16</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-08-27</th>\n",
       "      <td>1340</td>\n",
       "      <td>9</td>\n",
       "      <td>35</td>\n",
       "      <td>26</td>\n",
       "      <td>25</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-08-28</th>\n",
       "      <td>1341</td>\n",
       "      <td>2</td>\n",
       "      <td>33</td>\n",
       "      <td>26</td>\n",
       "      <td>25</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-08-29</th>\n",
       "      <td>1342</td>\n",
       "      <td>9</td>\n",
       "      <td>32</td>\n",
       "      <td>25</td>\n",
       "      <td>25</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-08-30</th>\n",
       "      <td>1343</td>\n",
       "      <td>9</td>\n",
       "      <td>34</td>\n",
       "      <td>26</td>\n",
       "      <td>25</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-08-31</th>\n",
       "      <td>1344</td>\n",
       "      <td>9</td>\n",
       "      <td>32</td>\n",
       "      <td>26</td>\n",
       "      <td>25</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1345 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Unnamed: 0  天气状况 最高温度 最低温度  白天风力风向  夜晚风力风向\n",
       "日期                                                    \n",
       "2018-01-01           0     2   22   12       1       1\n",
       "2018-01-01           1     2   22   12       1       1\n",
       "2018-01-02           2     2   22   15       1       1\n",
       "2018-01-03           3     2   23   15       1       1\n",
       "2018-01-04           4     2   21   16       1       1\n",
       "...                ...   ...  ...  ...     ...     ...\n",
       "2021-08-27        1340     9   35   26      25      22\n",
       "2021-08-28        1341     2   33   26      25      22\n",
       "2021-08-29        1342     9   32   25      25      22\n",
       "2021-08-30        1343     9   34   26      25      22\n",
       "2021-08-31        1344     9   32   26      25      22\n",
       "\n",
       "[1345 rows x 6 columns]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weather_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61a360e8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
